<?php
include 'Config.inc.php';
include 'CrmAccess.php';
include 'Library/Entity.php';

function GetAccess()
{
    return new CrmAccess(organizationServiceURL, liveIDUseranme, liveIDPassword, AppliesTo, false); //set to tru for screen debug
}

function Create(){
   
    try
    {    
        $access = GetAccess();

        $lead = new Entity("lead");
        $lead->AddAttribute("firstname", "My Php first lead", Types::string);
        $lead->AddAttribute("telephone2", "9222222", Types::string);
        $lead->AddAttribute("emailaddress1", "geral@rafaelrocha.net", Types::string);
        $lead->AddAttribute("leadsourcecode", 8, Types::picklist);  //website
        $lead->AddAttribute("donotsendmm", true, Types::boolean);
        $lead->AddAttribute("description", "oh yeah", Types::string);
        
        return $access->Create($lead);
       
    }
    catch (Exception $e)
    {
        echo $e->getMessage();
    }

}

function RetriveAndRetriveMultiple(){
   
    try
    {    
        $access = GetAccess();

        $result = $access->Retrive("<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'> <entity name='lead'> <attribute name='firstname'/> <order descending='false' attribute='firstname'/> </entity> </fetch>");
       
        //Pegar na lista de casas e anular as que já se encontra reservadas
         foreach ($result as $key=>$value) { //array de Preços
             echo $value->GetAttributeValueByName("firstname");
             echo "<p></p>";
         }
         
    }
    catch (Exception $e)
    {
        echo $e->getMessage();
    }
    
}

function Delete($guid)
{
    try
    {    
        $access = GetAccess();

        $access->Delete("lead", $guid );

    }
    catch (Exception $e)
    {
        echo $e->getMessage();
    }
    
}


?>

